package com.java.mail;

import java.util.Properties;

import javax.mail.Address;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class JavaMailTest {
	public static void main(String[] args) throws Exception {
		JavaMailTest.test1();
	}
	public static void test1() throws Exception{
			Properties props = new Properties();
			props.setProperty("mail.smtp.auth", "true");
			props.setProperty("mail.transport.protocol", "smtp");
			Session session = Session.getInstance(props);
			session.setDebug(true);
			
			Message message = new MimeMessage(session);  
			message.setText("你好吗");
			message.setSubject("这是主题");
			message.setFrom(new InternetAddress("samsara0650@163.com","昵称"));
			
			Transport transport = session.getTransport();
			transport.connect("smtp.163.com", 25, "samsara0650","Adgsqwj0650");
			//发送到某些邮箱
			transport.sendMessage(message,new Address[]{new InternetAddress("samsara0650@163.com")});
			transport.close();
	}
	//发送主题
/*	DEBUG: setDebug: JavaMail version 1.4.7
	DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
	DEBUG SMTP: useEhlo true, useAuth true
	DEBUG SMTP: trying to connect to host "smtp.163.com", port 25, isSSL false
	220 hz-b-163smtp2.163.com SMTP Server for Netease [466] 1a9a14c4-db12-4e5e-b4bc-ea283583449c
	DEBUG SMTP: connected to host "smtp.163.com", port: 25

	EHLO Minimalist-PC
	250-hz-b-163smtp2.163.com
	250-mail
	250-PIPELINING
	250-8BITMIME
	250-AUTH LOGIN PLAIN
	250-AUTH=LOGIN PLAIN
	250 STARTTLS 1a9a14c4-db12-4e5e-b4bc-ea283583449c
	DEBUG SMTP: Found extension "mail", arg ""
	DEBUG SMTP: Found extension "PIPELINING", arg ""
	DEBUG SMTP: Found extension "8BITMIME", arg ""
	DEBUG SMTP: Found extension "AUTH", arg "LOGIN PLAIN"
	DEBUG SMTP: Found extension "AUTH=LOGIN", arg "PLAIN"
	DEBUG SMTP: Found extension "STARTTLS", arg "1a9a14c4-db12-4e5e-b4bc-ea283583449c"
	DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM 
	DEBUG SMTP: AUTH LOGIN command trace suppressed
	DEBUG SMTP: AUTH LOGIN succeeded
	DEBUG SMTP: use8bit false
	MAIL FROM:<samsara0650@163.com>
	250 2.0.0 OK 1a9a14c4-db12-4e5e-b4bc-ea283583449c
	RCPT TO:<samsara0650@163.com>
	250 2.0.0 OK 1a9a14c4-db12-4e5e-b4bc-ea283583449c
	DEBUG SMTP: Verified Addresses
	DEBUG SMTP:   samsara0650@163.com
	DATA
	354 Start mail input; end with <CRLF>.<CRLF> 1a9a14c4-db12-4e5e-b4bc-ea283583449c
	From: =?GBK?B?6sezxg==?= <samsara0650@163.com>
	Message-ID: <4839036.0.1368238766811.JavaMail.BlueKey@Minimalist-PC>
	Subject: =?GBK?B?1eLKx9b3zOI=?=
	MIME-Version: 1.0
	Content-Type: text/plain; charset=GBK
	Content-Transfer-Encoding: base64

	xOO6w8Lw
	.
	250 2.0.0 OK 1a9a14c4-db12-4e5e-b4bc-ea283583449c
	QUIT
	221 2.0.0 Bye 1a9a14c4-db12-4e5e-b4bc-ea283583449c*/


}
